<template>
  <div class="watch-demo1">
    <h1>情况一:监视【ref】定义的【基本数据类型】数据</h1>
    <h2>当前求和为：{{ sum }}</h2>
    <button @click="addSum">click sum add 1</button>
  </div>
</template>

<script lang="ts" setup name="WatchDemo1">
import { ref, watch } from "vue";
let sum = ref(0);
function addSum() {
  sum.value += 1;
}
let stopWatch = watch(sum, (newValue, oldValue) => {
  console.log(`sum发生了变化，新值：${newValue}，旧值：${oldValue}`);
  if (newValue >= 10) {
    stopWatch();
    console.log("达到阈值，解除监视");
  }
});
</script>

<style>
.watch-demo1 {
  background-color: skyblue;
  box-shadow: 0 0 10px;
  border-radius: 10px;
  padding: 20px;
}
</style>